# -*- coding: utf-8 -*-

import os
import stat
from datetime import datetime

folder = "/data/images"
logs = {}

for root, dirs, files in os.walk(folder):
    for file in files:
        filepath = os.path.join(root, file)
        print(filepath)
        stat = os.stat(filepath)

        ctime = datetime.fromtimestamp(stat.st_ctime)

        year = ctime.year
        month = ctime.month

        logfile = "{}.{:02d}.log".format(year, month)

        if logfile not in logs:
            logs[logfile] = open(logfile, "a")

        logs[logfile].write(filepath + "\n")

for log in logs.values():
    log.close()
